from dataclasses import dataclass
from typing import Tuple, Any
from PIL.ImageCms import Flags
import numpy as np


class DicomTagInfo:
    def __init__(self):
        self.init_flag = False
        self.tags = {
            "window_center": None,
            "window_width": None,
            "intercept": None,
            "slope": None,
            "spacing": None,
            "rows": None,
            "columns": None,
            "manufacturer": None,
            "ex": None,
            'se': None,
            'mA': None,
            'kV': None,
            'thickness': None,
            "RescaleSlope": None,
            "RescaleIntercept": None,
            "image_orientation": None,
            "patient_position": None
        }

    def init_tag_info(self, ds):
        if self.init_flag is True:
            return
        self.tags = {
            "window_width": int(ds.get('WindowWidth', 0)),
            "window_center": int(ds.get('WindowCenter', 0)),
            "intercept": ds.get('RescaleIntercept', 0),
            "slope": ds.get('RescaleSlope', 1),
            "pixel_spacing": ds.get('PixelSpacing', [1, 1]),
            "rows": ds.get('Rows', 0),
            "columns": ds.get('Columns', 0),
            "manufacturer": ds.get('Manufacturer', 'Unknown'),
            "thickness": ds.get('SliceThickness', 'N/A'),
            "RescaleSlope": ds.get("RescaleSlope"),
            "RescaleIntercept": ds.get("RescaleIntercept"),
            "image_orientation": ds.get("ImageOrientationPatient"),
            "patient_position": ds.get("PatientPosition")
        }
        series_date = ds.get('SeriesDate', '')
        series_time = ds.get('SeriesTime', '')
        self.tags["ex"] = f'{series_date}{series_time}' if series_date and series_time else 'N/A'

        # 对于可能需要特殊处理的数值类型
        self.tags["se"] = ds.get('SeriesNumber', 0)
        self.tags["mA"] = ds.get('XRayTubeCurrent', 'N/A')
        self.tags["kV"] = ds.get('KVP', 'N/A')

        self.init_flag = True


